package com.ymatou.iapi.godfreight.testcase;

import java.util.ArrayList;
import java.util.Arrays;

import org.json.JSONObject;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.junit.internal.runners.TestMethod;

import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import com.mysql.fabric.xmlrpc.base.Array;
import com.ymatou.iapi.godfreight.parameter.batchQueryDeliveryPatternBean;
import com.ymatou.iapi.godfreight.service.batchQueryDeliveryPatternCall;
import com.ymatou.iapi.godfreightmgr.parameter.CreateCollectionGoodsAddressBean;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.GodfreightmgrService;
import com.ymttest.business.service.shenqi.GodmchManageCallService;
import com.ymttest.database.model.godfreight.DeliveryPatternConfig;
import com.ymttest.database.sqlwapper.godfreight.CollectionGoodsWapper;
import com.ymttest.utils.TestDataManager;
/**
*获取商户是否支持海外地址配置
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_batchQueryDeliveryPatterng{
	private static batchQueryDeliveryPatternBean bean;
	private static batchQueryDeliveryPatternCall call;
	private CollectionGoodsWapper CollectionGoodsWapper=new CollectionGoodsWapper();
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("获取商户是否支持海外地址配置");
	}

	@Before
	public void caseUp() {
		bean=new batchQueryDeliveryPatternBean();
		call=new batchQueryDeliveryPatternCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(call.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_batchQueryDeliveryPatterng_001() {
		Logger.start(true,"获取商户是否支持海外地址配置-商家配置快递配送和自提");
		try {
			Integer mchId_channl = GodmchManageCallService.CreateSellerMch();
            //开启运营
            GodfreightmgrService.setCollectionGoodsByAdminCall(mchId_channl, true);
            //添加一个自提地址
            CreateCollectionGoodsAddressBean createcollectiongoodsaddressBean = GodfreightmgrService.initCreateCollectionGoodsAddressBean(mchId_channl);
            int addressId = GodfreightmgrService.createcollectiongoodsaddressCall(createcollectiongoodsaddressBean);
            //开启自提
            GodfreightmgrService.setCollectionGoodsBySellerCall(mchId_channl, true);
            
            bean.setSellerIds(Arrays.asList(mchId_channl));
     
            bean.setAppId("appId_"+TestDataManager.getRandomIntNum(5));
            bean.setRequestId("11");
			call.setData(bean);
			call.callService();		
			
			Logger.verifyEquals("true", call.getSuccess(), "验证返回Success成功");
			Logger.verifyNotNull( call.getRequestId(), "验证返回RequestId");
            JsonArray deliveryPatternList=call.getDeliveryPatternList();
            Logger.verifyEquals(true, deliveryPatternList.size()>0, "验证返回deliveryPatternList有值");
			if(deliveryPatternList.size()>0) {
				for(int i=0;i<deliveryPatternList.size();i++)
				{
				   JsonObject return_obj=deliveryPatternList.get(i).getAsJsonObject();
				   Logger.verifyEquals(bean.getSellerIds().get(i).toString(), return_obj.get("sellerId").toString(), "验证sellerId="+return_obj.get("sellerId"));
					
				   DeliveryPatternConfig dp = CollectionGoodsWapper.selectDeliveryPatternConfig(bean.getSellerIds().get(i)).get(0);
                   Logger.verifyEquals(return_obj.get("collectionGoods").getAsBoolean(), dp.getCollectionGoods(), "验证商家开启自提");
                   Logger.verifyEquals(return_obj.get("expressDelivery").getAsBoolean(), dp.getExpressDelivery(), "验证商家开启快递");	
				}
		  }
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	@Ignore
	public void Tc_batchQueryDeliveryPatterng_002() {
		Logger.start(true,"获取商户是否支持海外地址配置-商家未配置快递配送和自提(不能都不设置)");
		try {
			Integer mchId_channl = GodmchManageCallService.CreateSellerMch();
            //开启运营
            GodfreightmgrService.setCollectionGoodsByAdminCall(mchId_channl, false);
            GodfreightmgrService.setExpressDeliveryBySellerCall(mchId_channl, false);
            //添加一个自提地址
            CreateCollectionGoodsAddressBean createcollectiongoodsaddressBean = GodfreightmgrService.initCreateCollectionGoodsAddressBean(mchId_channl);
            int addressId = GodfreightmgrService.createcollectiongoodsaddressCall(createcollectiongoodsaddressBean);
            //开启自提
           // GodfreightmgrService.setCollectionGoodsBySellerCall(mchId_channl, false);
            
            bean.setSellerIds(Arrays.asList(mchId_channl));
     
            bean.setAppId("appId_"+TestDataManager.getRandomIntNum(5));
            bean.setRequestId("11");
			call.setData(bean);
			call.callService();		
			
			Logger.verifyEquals("true", call.getSuccess(), "验证返回Success成功");
			Logger.verifyNotNull( call.getRequestId(), "验证返回RequestId");
            JsonArray deliveryPatternList=call.getDeliveryPatternList();
            Logger.verifyEquals(true, deliveryPatternList.size()>0, "验证返回deliveryPatternList有值");
			if(deliveryPatternList.size()>0) {
				for(int i=0;i<deliveryPatternList.size();i++)
				{
				   JsonObject return_obj=deliveryPatternList.get(i).getAsJsonObject();
				   Logger.verifyEquals(bean.getSellerIds().get(i).toString(), return_obj.get("sellerId").toString(), "验证sellerId="+return_obj.get("sellerId"));
					
				   DeliveryPatternConfig dp = CollectionGoodsWapper.selectDeliveryPatternConfig(bean.getSellerIds().get(i)).get(0);
                   Logger.verifyEquals(return_obj.get("collectionGoods").getAsBoolean(), dp.getCollectionGoods(), "验证商家开启自提");
                   Logger.verifyEquals(return_obj.get("expressDelivery").getAsBoolean(), dp.getExpressDelivery(), "验证商家开启快递");	
				}
		  }	
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_batchQueryDeliveryPatterng_003() {
		Logger.start(true,"获取商户是否支持海外地址配置-商家配置递配,未配置自提");
		try {
			Integer mchId_channl = GodmchManageCallService.CreateSellerMch();
            //开启运营
            GodfreightmgrService.setCollectionGoodsByAdminCall(mchId_channl, false);
            //添加一个自提地址
            CreateCollectionGoodsAddressBean createcollectiongoodsaddressBean = GodfreightmgrService.initCreateCollectionGoodsAddressBean(mchId_channl);
            int addressId = GodfreightmgrService.createcollectiongoodsaddressCall(createcollectiongoodsaddressBean);
            //开启自提
            GodfreightmgrService.setCollectionGoodsBySellerCall(mchId_channl, false);
            GodfreightmgrService.setExpressDeliveryBySellerCall(mchId_channl, true);
            
            bean.setSellerIds(Arrays.asList(mchId_channl));
     
            bean.setAppId("appId_"+TestDataManager.getRandomIntNum(5));
            bean.setRequestId("11");
			call.setData(bean);
			call.callService();		
			
			Logger.verifyEquals("true", call.getSuccess(), "验证返回Success成功");
			Logger.verifyNotNull( call.getRequestId(), "验证返回RequestId");
            JsonArray deliveryPatternList=call.getDeliveryPatternList();
            Logger.verifyEquals(true, deliveryPatternList.size()>0, "验证返回deliveryPatternList有值");
			if(deliveryPatternList.size()>0) {
				for(int i=0;i<deliveryPatternList.size();i++)
				{
				   JsonObject return_obj=deliveryPatternList.get(i).getAsJsonObject();
				   Logger.verifyEquals(bean.getSellerIds().get(i).toString(), return_obj.get("sellerId").toString(), "验证sellerId="+return_obj.get("sellerId"));
					
				   DeliveryPatternConfig dp = CollectionGoodsWapper.selectDeliveryPatternConfig(bean.getSellerIds().get(i)).get(0);
                   Logger.verifyEquals(return_obj.get("collectionGoods").getAsBoolean(), dp.getCollectionGoods(), "验证商家开启自提");
                   Logger.verifyEquals(return_obj.get("expressDelivery").getAsBoolean(), dp.getExpressDelivery(), "验证商家开启快递");	
				}
		  }		
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_batchQueryDeliveryPatterng_004() {
		Logger.start(true,"获取商户是否支持海外地址配置-商家未配置递配,配置自提");
		try {
			Integer mchId_channl = GodmchManageCallService.CreateSellerMch();
            //开启运营
            GodfreightmgrService.setCollectionGoodsByAdminCall(mchId_channl, true);
            //添加一个自提地址
            CreateCollectionGoodsAddressBean createcollectiongoodsaddressBean = GodfreightmgrService.initCreateCollectionGoodsAddressBean(mchId_channl);
            int addressId = GodfreightmgrService.createcollectiongoodsaddressCall(createcollectiongoodsaddressBean);
            //开启自提
            GodfreightmgrService.setCollectionGoodsBySellerCall(mchId_channl, true);
            GodfreightmgrService.setExpressDeliveryBySellerCall(mchId_channl, false);
            
            bean.setSellerIds(Arrays.asList(mchId_channl));
     
            bean.setAppId("appId_"+TestDataManager.getRandomIntNum(5));
            bean.setRequestId("11");
			call.setData(bean);
			call.callService();		
			
			Logger.verifyEquals("true", call.getSuccess(), "验证返回Success成功");
			Logger.verifyNotNull( call.getRequestId(), "验证返回RequestId");
            JsonArray deliveryPatternList=call.getDeliveryPatternList();
            Logger.verifyEquals(true, deliveryPatternList.size()>0, "验证返回deliveryPatternList有值");
			if(deliveryPatternList.size()>0) {
				for(int i=0;i<deliveryPatternList.size();i++)
				{
				   JsonObject return_obj=deliveryPatternList.get(i).getAsJsonObject();
				   Logger.verifyEquals(bean.getSellerIds().get(i).toString(), return_obj.get("sellerId").toString(), "验证sellerId="+return_obj.get("sellerId"));
					
				   DeliveryPatternConfig dp = CollectionGoodsWapper.selectDeliveryPatternConfig(bean.getSellerIds().get(i)).get(0);
                   Logger.verifyEquals(return_obj.get("collectionGoods").getAsBoolean(), dp.getCollectionGoods(), "验证商家开启自提");
                   Logger.verifyEquals(return_obj.get("expressDelivery").getAsBoolean(), dp.getExpressDelivery(), "验证商家开启快递");	
				}
		  }				
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_batchQueryDeliveryPatterng_005() {
		Logger.start(true,"获取商户是否支持海外地址配置-新建商户没有配置默认快递配送:true上门自提:false");
		try {
			Integer mchId_channl = GodmchManageCallService.CreateSellerMch();
			
            bean.setSellerIds(Arrays.asList(mchId_channl));
            bean.setAppId("appId_"+TestDataManager.getRandomIntNum(5));
            bean.setRequestId("11");
			call.setData(bean);
			call.callService();		
			
			Logger.verifyEquals("true", call.getSuccess(), "验证返回Success成功");
			Logger.verifyNotNull( call.getRequestId(), "验证返回RequestId");
            JsonArray deliveryPatternList=call.getDeliveryPatternList();
            Logger.verifyEquals(true, deliveryPatternList.size()>0, "验证返回deliveryPatternList有值");
			if(deliveryPatternList.size()>0) {
				for(int i=0;i<deliveryPatternList.size();i++)
				{
				   JsonObject return_obj=deliveryPatternList.get(i).getAsJsonObject();
				   Logger.verifyEquals(bean.getSellerIds().get(i).toString(), return_obj.get("sellerId").toString(), "验证sellerId="+return_obj.get("sellerId"));

                   Logger.verifyEquals(return_obj.get("collectionGoods").getAsBoolean(),false, "验证商家开启自提");
                   Logger.verifyEquals(return_obj.get("expressDelivery").getAsBoolean(), true, "验证商家开启快递");	
				}
		  }			
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_batchQueryDeliveryPatterng_005_1() {
		Logger.start(true,"获取商户是否支持海外地址配置-老商户没有配置默认快递配送:true上门自提:false");
		try {
			Integer mchId_channl =500822551;    
			
            bean.setSellerIds(Arrays.asList(mchId_channl));
            bean.setAppId("appId_"+TestDataManager.getRandomIntNum(5));
            bean.setRequestId("11");
			call.setData(bean);
			call.callService();		
			
			Logger.verifyEquals("true", call.getSuccess(), "验证返回Success成功");
			Logger.verifyNotNull( call.getRequestId(), "验证返回RequestId");
            JsonArray deliveryPatternList=call.getDeliveryPatternList();
            Logger.verifyEquals(true, deliveryPatternList.size()>0, "验证返回deliveryPatternList有值");
			if(deliveryPatternList.size()>0) {
				for(int i=0;i<deliveryPatternList.size();i++)
				{
				   JsonObject return_obj=deliveryPatternList.get(i).getAsJsonObject();
				   Logger.verifyEquals(bean.getSellerIds().get(i).toString(), return_obj.get("sellerId").toString(), "验证sellerId="+return_obj.get("sellerId"));

                   Logger.verifyEquals(return_obj.get("collectionGoods").getAsBoolean(),false, "验证商家开启自提");
                   Logger.verifyEquals(return_obj.get("expressDelivery").getAsBoolean(), true, "验证商家开启快递");	
				}
		  }			
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_batchQueryDeliveryPatterng_006() {
		Logger.start(true,"获取商户是否支持海外地址配置-商家编号列表为空");
		try {
           // bean.setSellerIds(Arrays.asList(mchId_channl));
            bean.setAppId("appId_"+TestDataManager.getRandomIntNum(5));
            bean.setRequestId("11");
			call.setData(bean);
			call.callService();			
			Logger.verifyEquals("false", call.getSuccess(), "验证返回Success成功");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_batchQueryDeliveryPatterng_007() {
		Logger.start(true,"获取商户是否支持海外地址配置-商家1配置递配,未配置自提 商家2配置递配,未配置自提 ");
		try {
			Integer mchId_channl = GodmchManageCallService.CreateSellerMch();
            //开启运营
            GodfreightmgrService.setCollectionGoodsByAdminCall(mchId_channl, false);
            //添加一个自提地址
            CreateCollectionGoodsAddressBean createcollectiongoodsaddressBean = GodfreightmgrService.initCreateCollectionGoodsAddressBean(mchId_channl);
            int addressId = GodfreightmgrService.createcollectiongoodsaddressCall(createcollectiongoodsaddressBean);
            //开启自提
            GodfreightmgrService.setCollectionGoodsBySellerCall(mchId_channl, false);
            GodfreightmgrService.setExpressDeliveryBySellerCall(mchId_channl, true);
            
            
			Integer mchId_channl2 = GodmchManageCallService.CreateSellerMch();
            //开启运营
            GodfreightmgrService.setCollectionGoodsByAdminCall(mchId_channl2, false);
            //添加一个自提地址
             createcollectiongoodsaddressBean = GodfreightmgrService.initCreateCollectionGoodsAddressBean(mchId_channl2);
            int addressId2 = GodfreightmgrService.createcollectiongoodsaddressCall(createcollectiongoodsaddressBean);
            //开启自提
            GodfreightmgrService.setCollectionGoodsBySellerCall(mchId_channl2, false);
            GodfreightmgrService.setExpressDeliveryBySellerCall(mchId_channl2, true);
            
            bean.setSellerIds(Arrays.asList(mchId_channl,mchId_channl2));
            bean.setAppId("appId_"+TestDataManager.getRandomIntNum(5));
            bean.setRequestId("11");
			call.setData(bean);
			call.callService();		
			
			Logger.verifyEquals("true", call.getSuccess(), "验证返回Success成功");
			Logger.verifyNotNull( call.getRequestId(), "验证返回RequestId");
            JsonArray deliveryPatternList=call.getDeliveryPatternList();
            Logger.verifyEquals(true, deliveryPatternList.size()>0, "验证返回deliveryPatternList有值");
			if(deliveryPatternList.size()>0) {
				for(int i=0;i<deliveryPatternList.size();i++)
				{
				   JsonObject return_obj=deliveryPatternList.get(i).getAsJsonObject();
				   Logger.verifyEquals(bean.getSellerIds().get(i).toString(), return_obj.get("sellerId").toString(), "验证sellerId="+return_obj.get("sellerId"));
					
				   DeliveryPatternConfig dp = CollectionGoodsWapper.selectDeliveryPatternConfig(bean.getSellerIds().get(i)).get(0);
                   Logger.verifyEquals(return_obj.get("collectionGoods").getAsBoolean(), dp.getCollectionGoods(), "验证商家开启自提");
                   Logger.verifyEquals(return_obj.get("expressDelivery").getAsBoolean(), dp.getExpressDelivery(), "验证商家开启快递");	
				}
		  }		
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_batchQueryDeliveryPatterng_008() {
		Logger.start(true,"获取商户是否支持海外地址配置-商家1配置未递配,配置自提 商家2配置未递配,配置自提 ");
		try {
			Integer mchId_channl = GodmchManageCallService.CreateSellerMch();
            //开启运营
            GodfreightmgrService.setCollectionGoodsByAdminCall(mchId_channl, true);
            //添加一个自提地址
            CreateCollectionGoodsAddressBean createcollectiongoodsaddressBean = GodfreightmgrService.initCreateCollectionGoodsAddressBean(mchId_channl);
            int addressId = GodfreightmgrService.createcollectiongoodsaddressCall(createcollectiongoodsaddressBean);
            //开启自提
            GodfreightmgrService.setCollectionGoodsBySellerCall(mchId_channl, true);
            GodfreightmgrService.setExpressDeliveryBySellerCall(mchId_channl, false);
            
            
			Integer mchId_channl2 = GodmchManageCallService.CreateSellerMch();
            //开启运营
            GodfreightmgrService.setCollectionGoodsByAdminCall(mchId_channl2, true);
            //添加一个自提地址
             createcollectiongoodsaddressBean = GodfreightmgrService.initCreateCollectionGoodsAddressBean(mchId_channl2);
            int addressId2 = GodfreightmgrService.createcollectiongoodsaddressCall(createcollectiongoodsaddressBean);
            //开启自提
            GodfreightmgrService.setCollectionGoodsBySellerCall(mchId_channl2, true);
            GodfreightmgrService.setExpressDeliveryBySellerCall(mchId_channl2, false);
            
            bean.setSellerIds(Arrays.asList(mchId_channl,mchId_channl2));
            bean.setAppId("appId_"+TestDataManager.getRandomIntNum(5));
            bean.setRequestId("11");
			call.setData(bean);
			call.callService();		
			
			Logger.verifyEquals("true", call.getSuccess(), "验证返回Success成功");
			Logger.verifyNotNull( call.getRequestId(), "验证返回RequestId");
            JsonArray deliveryPatternList=call.getDeliveryPatternList();
            Logger.verifyEquals(true, deliveryPatternList.size()>0, "验证返回deliveryPatternList有值");
			if(deliveryPatternList.size()>0) {
				for(int i=0;i<deliveryPatternList.size();i++)
				{
				   JsonObject return_obj=deliveryPatternList.get(i).getAsJsonObject();
				   Logger.verifyEquals(bean.getSellerIds().get(i).toString(), return_obj.get("sellerId").toString(), "验证sellerId="+return_obj.get("sellerId"));
					
				   DeliveryPatternConfig dp = CollectionGoodsWapper.selectDeliveryPatternConfig(bean.getSellerIds().get(i)).get(0);
                   Logger.verifyEquals(return_obj.get("collectionGoods").getAsBoolean(), dp.getCollectionGoods(), "验证商家开启自提");
                   Logger.verifyEquals(return_obj.get("expressDelivery").getAsBoolean(), dp.getExpressDelivery(), "验证商家开启快递");	
				}
		  }		
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_batchQueryDeliveryPatterng_009() {
		Logger.start(true,"获取商户是否支持海外地址配置-商家1、商家2配置递配,配置自提 ");
		try {
			Integer mchId_channl = GodmchManageCallService.CreateSellerMch();
            //开启运营
            GodfreightmgrService.setCollectionGoodsByAdminCall(mchId_channl, true);
            //添加一个自提地址
            CreateCollectionGoodsAddressBean createcollectiongoodsaddressBean = GodfreightmgrService.initCreateCollectionGoodsAddressBean(mchId_channl);
            int addressId = GodfreightmgrService.createcollectiongoodsaddressCall(createcollectiongoodsaddressBean);
            //开启自提
            GodfreightmgrService.setCollectionGoodsBySellerCall(mchId_channl, true);
            GodfreightmgrService.setExpressDeliveryBySellerCall(mchId_channl, true);
            
            
			Integer mchId_channl2 = GodmchManageCallService.CreateSellerMch();
            //开启运营
            GodfreightmgrService.setCollectionGoodsByAdminCall(mchId_channl2, true);
            //添加一个自提地址
             createcollectiongoodsaddressBean = GodfreightmgrService.initCreateCollectionGoodsAddressBean(mchId_channl2);
            int addressId2 = GodfreightmgrService.createcollectiongoodsaddressCall(createcollectiongoodsaddressBean);
            //开启自提
            GodfreightmgrService.setCollectionGoodsBySellerCall(mchId_channl2, true);
            GodfreightmgrService.setExpressDeliveryBySellerCall(mchId_channl2, true);
            
            bean.setSellerIds(Arrays.asList(mchId_channl,mchId_channl2));
            bean.setAppId("appId_"+TestDataManager.getRandomIntNum(5));
            bean.setRequestId("11");
			call.setData(bean);
			call.callService();		
			
			Logger.verifyEquals("true", call.getSuccess(), "验证返回Success成功");
			Logger.verifyNotNull( call.getRequestId(), "验证返回RequestId");
            JsonArray deliveryPatternList=call.getDeliveryPatternList();
            Logger.verifyEquals(true, deliveryPatternList.size()>0, "验证返回deliveryPatternList有值");
			if(deliveryPatternList.size()>0) {
				for(int i=0;i<deliveryPatternList.size();i++)
				{
				   JsonObject return_obj=deliveryPatternList.get(i).getAsJsonObject();
				   Logger.verifyEquals(bean.getSellerIds().get(i).toString(), return_obj.get("sellerId").toString(), "验证sellerId="+return_obj.get("sellerId"));
					
				   DeliveryPatternConfig dp = CollectionGoodsWapper.selectDeliveryPatternConfig(bean.getSellerIds().get(i)).get(0);
                   Logger.verifyEquals(return_obj.get("collectionGoods").getAsBoolean(), dp.getCollectionGoods(), "验证商家开启自提");
                   Logger.verifyEquals(return_obj.get("expressDelivery").getAsBoolean(), dp.getExpressDelivery(), "验证商家开启快递");	
				}
		  }		
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}